Infosys AI Interview
C# & .NET Core

My First AI Interview Experience at Infosys: Questions, Answers & C# Examples

Interview context and pacing

Summary: Yes you read it right, Now no human interaction in interview process of Infosys, I received email from hirepro to join interview and interview is taken by AI bot, The interview began with my technical background. The 5 second pause instruction is given in instruction guide in advance, The AI Bot noted that even a brief pause—around five seconds—would be treated as candidate answered and they would auto‑submit and even if not answered it will move ahead for the next question. This meant responses needed to be concise and confident.

Tip: Practice crisp, structured answers. Lead with the concept, follow with a short example, and end with a practical use case.


Abstract class vs interface in C#

Question: What is the difference between an abstract class and an interface? When should we use each?

  • Abstract class: Provides shared base behavior and state; can include implemented methods and fields.
  • Interface: Defines a contract only; no implementation or state (until default interface methods in newer C# versions, used sparingly).
  • Use abstract class: When types share core behavior and a common base is meaningful.
  • Use interface: When multiple unrelated types must expose the same capability.
// Abstract class + interface example
public abstract class Animal
{
    public abstract void Speak();
    public void Eat() => Console.WriteLine("Eating...");
}

public interface IFlyable
{
    void Fly();
}

public class Bird : Animal, IFlyable
{
    public override void Speak() => Console.WriteLine("Chirp Chirp");
    public void Fly() => Console.WriteLine("Flying high!");
}

Database normalization

Question: Explain normalization and its uses.

  • Purpose: Reduce redundancy, improve integrity, and prevent update anomalies.
  • 1NF: Atomic values; no repeating groups.
  • 2NF: Remove partial dependencies on a composite key.
  • 3NF: Remove transitive dependencies; non‑key attributes depend only on the key.

Repository pattern in C#

Question: What is the repository pattern and why use it?

  • Goal: Abstract data access, centralize queries, and enable testability.
  • Benefit: Clear separation of concerns and easier mocking in unit tests.
public interface IProductRepository
{
    IEnumerable<Product> GetAll();
    Product GetById(int id);
}

public class ProductRepository : IProductRepository
{
    private readonly DbContext _context;
    public ProductRepository(DbContext context) => _context = context;

    public IEnumerable<Product> GetAll() => _context.Set<Product>().ToList();
    public Product GetById(int id) => _context.Set<Product>().Find(id);
}

Separation of concerns in MVC

Question: Explain separation of concerns in MVC.

  • Model: Domain/data + business rules.
  • View: Presentation/UI only.
  • Controller: Orchestrates requests, binds models, selects views.

Middleware in .NET Core

Question: What is middleware and how does it work?

  • Definition: Pipeline components that process HTTP requests/responses.
  • Examples: Authentication, logging, exception handling, routing.
public class CustomMiddleware
{
    private readonly RequestDelegate _next;
    public CustomMiddleware(RequestDelegate next) => _next = next;

    public async Task Invoke(HttpContext context)
    {
        Console.WriteLine("Request handled");
        await _next(context);
    }
}

// In Program.cs / Startup.cs
// app.UseMiddleware<CustomMiddleware>();

Async/await advantages in .NET Core

Question: Why use async/await?

  • Non‑blocking: Frees threads during I/O, improving scalability.
  • Throughput: Better resource utilization under load.
public async Task<string> GetDataAsync()
{
    await Task.Delay(2000); // simulate I/O
    return "Data fetched asynchronously!";
}

NUnit unit testing

Question: Explain unit testing with NUnit.

  • Focus: Validate small units (methods/classes) in isolation.
  • Key attributes: [TestFixture], [SetUp], [Test].
[TestFixture]
public class CalculatorTests
{
    [Test]
    public void Add_ReturnsCorrectSum()
    {
        var calc = new Calculator();
        Assert.AreEqual(5, calc.Add(2, 3));
    }
}

DbContext usage in Entity Framework Core

Question: What is DbContext and how should it be used?

  • Role: Manages connection, change tracking, and CRUD operations.
  • Best practice: Inject via DI; scope per request in web apps.
  • Read‑only queries: Use AsNoTracking() to skip tracking overhead.

EF Core performance and bottlenecks

Question: How do you improve performance when EF Core becomes a bottleneck?

  • Optimize queries: Project only needed columns; prefer Select over materializing entire entities.
  • Tracking control: Use AsNoTracking() for read‑heavy endpoints.
  • Batching: Group writes; avoid chatty save cycles.
  • Compiled queries: Cache query plans for hot paths.
  • Indexes & DB tuning: Ensure proper indexing and analyze execution plans.
  • Caching: Add application‑level caching for frequently accessed data.
  • Profiling: Use logging/profilers to find N+1 queries and slow joins.
// Example: AsNoTracking + projection
var products = await _context.Products
    .AsNoTracking()
    .Select(p => new ProductDto { Id = p.Id, Name = p.Name })
    .ToListAsync();



Tags:

C# interview questions .NET Core middleware repository pattern tutorial MVC separation of concerns Entity Framework Core performance database normalization NUnit unit testing DbContext optimization